package com.kws.merchant.controller;


import com.kws.common.security.auth.AuthUtil;
import com.kws.merchant.domain.AfterSalesHistory;
import com.kws.merchant.domain.AfterSalesMalfunction;
import com.kws.merchant.domain.po.AfterSalesMalfunctionPo;
import com.kws.merchant.service.AfterSalesMalfunctionService;
import com.kws.system.api.domain.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import com.kws.common.core.domain.R;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
 * 售后-故障单(AfterSalesMalfunction)表控制层
 *
 * @author yxy
 * @since 2024-10-22 19:23:09
 */
@RestController
@Api(tags = "售后-故障单(AfterSalesMalfunction)")
@RequestMapping("afterSalesMalfunction")
public class AfterSalesMalfunctionController {
    /**
     * 服务对象
     */
    @Resource
    private AfterSalesMalfunctionService afterSalesMalfunctionService;

    @PostMapping("/page")
    @ApiOperation(value = "分页查询列表")
    public R<Page<AfterSalesMalfunction>> pageList(@RequestBody AfterSalesMalfunctionPo afterSalesMalfunctionPo) {
        return R.ok(afterSalesMalfunctionService.pageList(afterSalesMalfunctionPo));
    }

    @GetMapping("/detailById/{id}")
    @ApiOperation(value = "通过主键查询单条数据")
    public R<AfterSalesMalfunction> detailById(@PathVariable Long id) {
        return R.ok(afterSalesMalfunctionService.detailById(id));
    }


    @PostMapping("/add")
    @ApiOperation(value = "新增故障单")
    public R add(@RequestBody AfterSalesMalfunction afterSalesMalfunction) {
        SysUser sysUser = AuthUtil.getLoginUser().getSysUser();
        Long companyId = sysUser.getCompanyId();
        afterSalesMalfunction.setMerchantId(companyId);
        afterSalesMalfunction.setMalfunctionNo("GZ"+ UUID.randomUUID());
        afterSalesMalfunction.setStatus(0);//未处理
        return R.ok(afterSalesMalfunctionService.save(afterSalesMalfunction));
    }

    @PostMapping("/dispose")
    @ApiOperation(value = "处理故障单")
    public R dispose(@RequestBody AfterSalesMalfunction afterSalesMalfunction) {
        return R.ok(afterSalesMalfunctionService.dispose(afterSalesMalfunction));
    }


    @PostMapping("/delete")
    @ApiOperation(value = "删除数据")
    public R delete(@RequestBody List<Long> idList) {
        return R.ok(afterSalesMalfunctionService.delete(idList));
    }
}
